package com.xindaoapp.framework.application;

import android.app.Application;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.xindaoapp.framework.R;
import com.xindaoapp.framework.api.MoccaApi;
import com.xindaoapp.framework.api.MoccaApiImpl;

public class XindaoApplication extends Application {
	private MoccaApi mMoccaApi;
	private static XindaoApplication mIns;

//	private SharePopupWindow mSharePopupWindow;
	
//	private IDBManager mIdbManager;
//	private IQueue iQueue;
	private boolean isWifiSwitch;
	private String picurl;
	
	private Context context;
	
	public static final Handler mHandler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
		}

	};
	public void setPicurl(String picurl) {
		this.picurl = picurl;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		context=getApplicationContext();
		mIns = this;
//		iQueue = new QueueManager(this);
		mMoccaApi = new MoccaApiImpl();
//		mIdbManager = new DBManagerImpl(this);
		initImageLoader();
//		mSharePopupWindow=new SharePopupWindow(picurl);
//		JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志
//		JPushInterface.init(this);
	}

	public boolean getIsSwitch() {
		return isWifiSwitch;
	}
	
//	public IQueue getQueue() {
//		return iQueue;
//	}
//	
//	public SharePopupWindow getSharePopupWindow() {
//		return mSharePopupWindow;
//	}

	public static XindaoApplication get() {
		return mIns;
	}

//	public IDBManager getDBManager() {
//		return mIdbManager;
//	}
	
	public MoccaApi getMoccaApi() {
		return mMoccaApi;
	}

	protected void initImageLoader() {
		DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder().resetViewBeforeLoading(true)
				.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).bitmapConfig(Bitmap.Config.RGB_565)
				.showStubImage(R.drawable.picture_loading).cacheInMemory(true).cacheOnDisc(true).build();

		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
				.defaultDisplayImageOptions(defaultOptions).discCacheSize(50 * 1024 * 1024)//
				.discCacheFileCount(100)// 缓存一百张图片
				.build();
		ImageLoader.getInstance().init(config);
	}

	public Context getContext() {
		return context;
	}
	public void setContext(Context context) {
		this.context = context;
	}
}
